window.onload = function() {
	var s = document.getElementById("s_code");
	var c = document.getElementById("c_code");
	var cell = document.getElementById("cell");
	var r = document.getElementById("ident");
	var y = document.getElementById("yzm");
	var u = document.getElementById("user");
	var tip = document.getElementById("tip");
	var user = document.getElementById("user");
	var boolpwd = false;
	var boolname = false;
	var boolrpwd = false;
	var boolph = false;
	var boolcode = false;

	s.onkeyup = function() {
		if(s.value == "密码") {
			s.type = "text";
		} else {
			s.type = "password";
		}

	}
	c.onkeyup = function() {
		if(c.value == "密码") {
			c.type = "text";
		} else {
			c.type = "password";
		}
	}

	user.onblur = function() {
		var name = /^[a-zA-Z0-9_-]{4,16}$/;
		var li1 = document.getElementById("li1");
		if(!name.test(user.value)) {
			li1.innerHTML = "请输入4~16位的字母或数字";
		} else {
			li1.innerHTML = "";
			boolname = true;
		}
	}

	s.onblur = function() {
		var li2 = document.getElementById("li2");
		var pwd = /(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{8,}/;
		if(!pwd.test(s.value)) {
			li2.innerHTML = "请输入8位以上的字母或数字";
		} else {
			li2.innerHTML = "";
			boolpwd = true;
		}
	}

	c.onblur = function() {
		var li3 = document.getElementById("li3");
		if(s.value == c.value) {
			li3.innerHTML = "";
			boolrpwd = true;
		} else {
			li3.innerHTML = "两次输入的密码不一致";
		}
	}
	cell.onblur = function() {
		var ce = /^0?(13|14|15|17|18|19)[0-9]{9}$/;
		var li4 = document.getElementById("li4");
		if(!ce.test(cell.value)) {
			li4.innerHTML = "请输入正确的手机号";
		} else {
			li4.innerHTML = "";
			boolph = true;
		}
	}
	r.onblur = function() {
		if(ident.value == y.innerHTML) {
			tip.innerHTML = "";
			boolcode = true;
		} else {
			tip.innerHTML = "验证码不正确";
		}
	}

	function randomNum(min, max) {
		return Math.floor(Math.random() * (max - min) + min);
	}

	var str = "abcdefghijklmnopqrstuvwxyz123456789";

	for(var i = 0; i < 4; i++) {
		var txt = str[randomNum(0, str.length)];
		y.innerHTML += txt;
	}

	y.onclick = function() {
		y.innerHTML = "";
		for(var i = 0; i < 4; i++) {
			var txt = str[randomNum(0, str.length)];
			y.innerHTML += txt;
		}

	}
	var sub = document.getElementById("submits");
	var con = document.getElementById("con");
	var inp = con.getElementsByTagName("form")[0].getElementsByTagName("input");
	var att = [];
	var tnt = localStorage.getItem("con");
	var bool = false;

	sub.onclick = function() {
		if(boolpwd == true && boolrpwd == true && boolph == true && boolcode == true && boolname == true) {
			alert("注册成功");
			var a1 = user.value;
			var a2 = s.value;
			var a3 = c.value;
			var a4 = cell.value;
			var a5 = r.value;

			var obj = {
				a1: a1,
				a2: a2,
				a3: a3,
				a4: a4,
				a5: a5,

			};
			att.push(obj);
			var tnt = JSON.stringify(att);
			localStorage.setItem("con", tnt);
			bool = true;
		} else {
			bool = false;
			alert('请补全信息');

		}
	}

	$(".container>form").submit(function() {
		return bool;
	});

}